<?php
/**
 * 钉钉机器人测试
 *
 * Created by PhpStorm.
 * User: sunqiang
 * Date: 2018/12/29
 * Time: 上午11:17
 */

namespace App\Http\Controllers;


class DingController extends Controller
{
    public function __invoke($type)
    {
        switch ($type) {
            case 'text':
                $this->text();
                break;
            case 'link':
                $this->link();
                break;
            case 'markdown':
                $this->markdown();
                break;
            default:
                echo '类型不存在';
        }
    }

    /**
     * 发送文本消息测试
     *
     *
     */
    private function text()
    {
        $atMobiles = '17612906056';
        $message = '我有明珠一颗 @' . $atMobiles . ' 照破山河万朵';
        $result = dingText($message, $atMobiles);
        if ($result->errmsg == 'ok') {
            echo '艾特' . $atMobiles . '的消息***' . $message . '***发送成功';
        }
    }

    /**
     * 发送链接消息测试
     *
     *
     */
    private function link()
    {
        if (dingLink()->errmsg == 'ok') {
            echo 'link发送成功';
        }
    }

    // 发送markdown消息测试
    private function markdown()
    {
        if (dingMarkdown()->errmsg == 'ok') {
            echo 'markdown消息发送成功';
        }
    }

}